import torch

a = torch.rand(2, 2) * 10
print(a) # ==> tensor([[8.9470, 4.6770],[3.2196, 0.2898]])
a = a.clamp(2, 5)
print(a) # ==> tensor([[5.0000, 4.6770],[3.2196, 2.0000]])